home *** CD-ROM | disk | FTP | other *** search
Modula Definition | 1989-06-18 | 3.4 KB | 105 lines | [TEXT/MPS ] |
- (****************************************************)
- (* *)
- (* file: SimulationToolbox.d *)
- (* *)
- (* This module defines a set of subroutines for *)
- (* doing discrete event simulation, using a *)
- (* "process" viewpoint. *)
- (* *)
- (* Written in SemperSoft Modula-2 v.1.1.2 *)
- (* *)
- (* Allen Stenger May 1989 *)
- (* *)
- (****************************************************)
-
- DEFINITION MODULE SimulationToolbox;
-
- FROM SYSTEM IMPORT ADDRESS;
-
- TYPE
- Duration = CARDINAL; (* in units of time as
- defined by the caller *)
- Starter = PROCEDURE ( ADDRESS );
- SimulationQueue;
- Requester;
-
- (* CreateNewThread starts a new thread of execution in
- the simulation, beginning execution at routine
- starter, which is passed the address of a parameter
- block so that it knows what to do. The worksize is
- the size (in bytes) of the stack to be allocated for
- this thread. The calling thread is suspended and
- the new thread beings execution. (Note that the
- calling thread will be resumed to complete its
- execution for the current time before the time can
- be advanced.) Initial execution of the program is
- also considered to be a thread.
- *)
- PROCEDURE CreateNewThread( starter : Starter;
- parameterAddress : ADDRESS;
- worksize : CARDINAL );
-
- (* Hold is called to simulate a delay (while work is
- being simulated). The calling thread is suspended
- until this much simulated time has passed. The
- order of execution of threads becoming active at
- the same simulated time is not defined. Hold(0)
- is legal.
- *)
- PROCEDURE Hold( howLong : Duration );
-
- (* HaltSimulation is called at the end of the
- simulation run and causes all threads to exit.
- *)
- PROCEDURE HaltSimulation;
-
- (* HaltThread is called by a thread to end its own
- existence.
- *)
- PROCEDURE HaltThread;
-
- (* CurrentTime returns the current simulated time (time
- starts at 0).
- *)
- PROCEDURE CurrentTime() : Duration;
-
- (****************************************************)
- (* Queueing routines *)
- (****************************************************)
-
- (* InitializeQueue is called to create and initialize
- a queue.
- *)
- PROCEDURE InitializeQueue( VAR q : SimulationQueue );
-
- (* PlaceOrder is called to place the caller on a queue
- for service. The parameterAddress is the address of
- a parameter block that will be interpreted by the
- server to determine the type of service needed.The
- caller is suspended until reactivated by the server,
- usually at the end of service. More than one caller
- may be queued; the order of service is FIFO.
- *)
- PROCEDURE PlaceOrder( q : SimulationQueue;
- parameterAddress : ADDRESS );
-
- (* Serve is called by a server to obtain the next order
- to serve. The identity of the requester is returned
- so that the server may resume the requester when
- done. If there are no orders, the caller is
- suspended until an order arrives. More than one
- server may wait on the same queue; the order in
- which orders are given to servers is FIFO.
- *)
- PROCEDURE Serve( q: SimulationQueue;
- VAR parameterAddress : ADDRESS;
- VAR r : Requester );
-
- (* Reactivate is called by a server to resume execution
- of the requester. The requester becomes ready to
- run at the current time. The caller continues to
- run until it gives up control.
- *)
- PROCEDURE Reactivate( r : Requester );
-
- END SimulationToolbox.